package com.firemoss.atonement.changewatcher.valuecomparison
{
	import flash.utils.Dictionary;

	public class DictionaryComparitor extends AbstractComparitor implements IValueComparitor
	{
		public function DictionaryComparitor()
		{
		}
		
		public function compare(originalValue:*, newValue:*):*
		{
			if ( originalValue is Dictionary && newValue is Dictionary )
			{
				var orig : Dictionary = originalValue as Dictionary
				var newVal : Dictionary = newValue as Dictionary
					
				if ( orig != null && newVal != null )
				{
					var i : *
					// compare orig to new
					for ( i in orig )
					{
						// Not in
						if ( newVal[ i ] == null )
						{
							return newVal
						}
						// In, but different
						else if ( compareNestedValues( orig[ i ], newVal [ i ] ) != null )
						{
							return newVal
						}
					}
					// compare new to orig (may have added values)
					for ( i in newVal )
					{
						// Not in
						if ( orig[ i ] == null )
						{
							return newVal
						}
						// In, but different
						else if ( compareNestedValues( orig[ i ], newVal [ i ] ) != null )
						{
							return newVal
						}
					}
				}
				else if ( newVal != null )
				{
					return newVal
				}
				else
				{
					return null
				}
			}
			
			return null
		}
	}
}